/*
    BibleNotebook - A bible reader software
    Copyright (C) 2014  Williams Fernando Lopez

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
 */

/*
 * InfoViewerDialog.java
 * Created on Dec 26, 2013, 3:32:22 PM
 */

package com.simplebible.ui.components;

import com.simplebible.Main;
import wl.util.TextResourcesUtil;
import com.simplebible.dictionary.IDictionary;
import com.simplebible.bible.objects.Bible;

/**
 *
 * @author Williams Lopez
 */
public class InfoViewerDialog extends javax.swing.JDialog {

    private static InfoViewerDialog me =  null;



    /** Creates new form InfoViewerDialog */
    private InfoViewerDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationByPlatform(true);
        jTextPane1.setContentType("text/html");
    }

    public static void showDialog(Bible bible){
        if(me == null){
            me = new InfoViewerDialog(Main.getMainFrame(), true);
        }
        me.setBibleInfo(bible);
        me.setVisible(true);
    }

    public static void showDialog(IDictionary iDictionary) {
        if (me == null) {
            me = new InfoViewerDialog(Main.getMainFrame(), true);
        }
        me.setDictionaryInfo(iDictionary);
        me.setVisible(true);
    }

    public static void showDialog(String title, String htmlInfo){
        if (me == null) {
            me = new InfoViewerDialog(Main.getMainFrame(), true);
        }
        me.setGenericInfo(title,htmlInfo);
        me.setVisible(true);
    }


    private void setGenericInfo(String title, String htmlInfo){
        this.setTitle(title);
        jTextPane1.setText(htmlInfo);
    }

    private void setDictionaryInfo(IDictionary dict){
        StringBuilder sb = new StringBuilder();
        sb.append("<h1>");
        sb.append(dict.getDictionaryName());
        sb.append("</h1>");

        sb.append("<p>");
        sb.append("Copyright info:<br/>");
        if(dict.getDictionaryCopyright()!=null){
            sb.append(dict.getDictionaryCopyright());
            sb.append("<br/>");
        }
        if(dict.getDictionaryUrl()!=null){
            sb.append(dict.getDictionaryUrl());
            sb.append("<br/>");
        }

        sb.append("</p>");

        sb.append("<p>");
        sb.append("About:<br/>");
        if(dict.getDictionaryDescription()==null){
            sb.append(TextResourcesUtil.getText("no_info_available"));
        }else{
            sb.append(dict.getDictionaryDescription());
        }

        sb.append("</p>");
        jTextPane1.setText(sb.toString());
    }

    private void setBibleInfo(Bible bible){
        StringBuilder sb = new StringBuilder();
        sb.append("<h1>");
        sb.append(bible.getHumanName());
        sb.append("</h1>");

        sb.append("<p>");
        sb.append("Copyright info:<br/>");
        if(bible.getCopyRight()!=null){
            sb.append(bible.getCopyRight());
            sb.append("<br/>");
        }
        if(bible.getCopyRightContactAdrs()!=null){
            sb.append(bible.getCopyRightContactAdrs());
            sb.append("<br/>");
        }
        if(bible.getCopyRightContactName()!=null){
            sb.append(bible.getCopyRightContactName());
            sb.append("<br/>");
        }
        if(bible.getCopyRightContactNote()!=null){
            sb.append(bible.getCopyRightContactNote());
            sb.append("<br/>");
        }
        sb.append("</p>");

        sb.append("<p>");
        sb.append("About:<br/>");
        if(bible.getAbout()==null){
            sb.append(TextResourcesUtil.getText("no_info_available"));
        }else{
            sb.append(bible.getAbout());
        }
        
        sb.append("</p>");
        jTextPane1.setText(sb.toString());

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        buttonLabel1 = new wl.ui.ButtonLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jScrollPane1.setBorder(null);

        jTextPane1.setEditable(false);
        jScrollPane1.setViewportView(jTextPane1);

        buttonLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/simplebible/ui/img/dialog-close.png"))); // NOI18N
        buttonLabel1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonLabel1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(533, Short.MAX_VALUE)
                .addComponent(buttonLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 540, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(buttonLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonLabel1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonLabel1ActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_buttonLabel1ActionPerformed



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private wl.ui.ButtonLabel buttonLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables

}
